$(function () {
    $(window).keydown(function (e) {
        if (e.keyCode == 13) {
            $('.log_btn').click();
        }
    })
    $('.log_btn').click(function () {
        var mobile = $('#mobile').val();
        var password = $('#password').val();
        if (mobile == '') {
            tispFun('请输入账号');
            return;
        }
        if (password == '') {
            tispFun('请输入密码');
            return;
        }
        loadingShow();
        $.ajax({
            url: 'api/user/login_pass',
            type: 'post',
            data: {mobile: mobile, password: password},
            dataType: 'json',
            timeout: 2000,
            success: function (rel) {
                loadingHide()
                if (rel.code == 0) {
                    localStorage.setItem('_u_t', rel.data.token);
                    window.location.href = '/'
                } else {
                    tispFun(rel.msg);
                }
            },
            error: function () {
                loadingHide()
                tispFun('网络错误,稍后再试');
            },
            complete: function () {
                loadingHide()
            }
        });
    })
})
